package com.lions.client.view.basepanel;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.lions.client.controller.Controller;
import com.lions.client.model.AudioOutput;
import com.lions.client.model.Model;
import com.lions.client.view.mappanel.MapPanel;
import com.lions.client.view.popup.MyPopupPanel;

public class ConfigurationsPanel extends VerticalPanel{
	public ConfigurationsPanel(Model m, MapPanel p, String basePicLoc,
			final int plain1X, final int plain1Y, 
			final int plain2X, final int plain2Y, 
			final int plain3X, final int plain3Y, 
			final int airlockX, final int airlockY, 
			final int controlX, final int controlY, 
			final int powerX, final int powerY, 
			final int foodX, final int foodY, 
			final int dormX, final int dormY, 
			final int canteenX, final int canteenY, 
			final int sanX, final int sanY){

		this.plain1X = plain1X; 
		this.plain1Y = plain1Y; 
		this.plain2X = plain2X;
		this.plain2Y = plain2Y; 
		this.plain3X = plain3X;
		this.plain3Y = plain3Y; 
		this.airlockX = airlockX;
		this.airlockY = airlockY; 
		this.controlX = controlX;
		this.controlY = controlY; 
		this.powerX = powerX;
		this.powerY = powerY; 
		this.foodX = foodX;
		this.foodY = foodY; 
		this.dormX = dormX;
		this.dormY = dormY; 
		this.canteenX = canteenX;
		this.canteenY = canteenY; 
		this.sanX = sanX;
		this.sanY = sanY;

		basePicFile = basePicLoc;
		model = m;
		mapPanel = p;
		commit = new Button("COMMIT", new ClickHandler(){
			public void onClick(ClickEvent event) {
				Window.alert("Still Working on this: Will commit base changes to master list");
				//model.commitBuild(some2dContainer);
			}
		});
		commit.setEnabled(false);
		commit.setVisible(false);

		revert = new Button("REVERT", new ClickHandler(){
			public void onClick(ClickEvent event) {
				mapPanel.populate();
				commit.setEnabled(false);
				commit.setVisible(false);
				revert.setEnabled(false);
				revert.setVisible(false);
			}
		});
		revert.setEnabled(false);
		revert.setVisible(false);
		bottom = initStandardButtons(commit, revert);
		preview = new Button("Preview", new ClickHandler(){
			public void onClick(ClickEvent event) {
				if(model.checkMin()){
					MinBaseBuilder constructor = new MinBaseBuilder(model, mapPanel, 
							plain1X, plain1Y, 
							plain2X, plain2Y, 
							plain3X, plain3Y, 
							airlockX, airlockY, 
							controlX, controlY, 
							powerX, powerY, 
							foodX, foodY, 
							dormX, dormY, 
							canteenX, canteenY, 
							sanX, sanY);
					constructor.build();
					commit.setEnabled(true);
					commit.setVisible(true);
					revert.setEnabled(true);
					revert.setVisible(true);
				} else { 
					new MyPopupPanel("Base Configuration",
							"Minimum Base Configuration Not Met\n");
					new AudioOutput().playBaseError();
				}
			}
		});
		//controller.getSpeech().addVoiceHandler(build, "build base");
		preview.setPixelSize(100, 100);
		preview.setStyleName("buttonstyle");
		top = new HorizontalPanel();
		top.add(new Image(basePicFile));
		top.add(preview);
		add(top);
		add(bottom);



	}

	public HorizontalPanel initStandardButtons(Button c, Button r){
		HorizontalPanel tempPanel = new HorizontalPanel();
		tempPanel.setPixelSize(200, 100);
		c.setPixelSize(100, 100);
		r.setPixelSize(100, 100);
		c.setStyleName("buttonstyle");
		r.setStyleName("buttonstyle");
		tempPanel.add(c);
		tempPanel.add(r);
		return tempPanel;
	}
	private Button preview;
	private Button revert;
	private Button commit;
	private HorizontalPanel top;
	private HorizontalPanel bottom;
	private MapPanel mapPanel;
	private Model model;
	private String basePicFile;
	int plain1X, plain1Y, plain2X, plain2Y, plain3X, plain3Y, airlockX, airlockY; 
	int controlX, controlY, powerX, powerY, foodX, foodY, dormX, dormY; 
	int canteenX, canteenY, sanX, sanY;
}
